package IO;

import javax.sound.midi.Sequencer;
import java.io.*;
import java.util.Enumeration;
import java.util.Vector;

public class fengehebing {
    public static void main(String[] args) {
/* File file = new File("D:\\360安全浏览器下载\\496.76-notebook-win10-win11-64bit-international-dch-whql.exe");
                 fenge(file,1024*1024*40);

 */


        try {
            InputStream in1 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part01.rar"));
            InputStream in2 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part02.rar"));
            InputStream in3 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part03.rar"));
            InputStream in4 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part04.rar"));
            InputStream in5 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part05.rar"));
            InputStream in6 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part06.rar"));
            InputStream in7 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part07.rar"));
            InputStream in8 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part08.rar"));
            InputStream in9 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part09.rar"));
            InputStream in10 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part10.rar"));
            InputStream in11 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part11.rar"));
            InputStream in12 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part12.rar"));
            InputStream in13 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part13.rar"));
            InputStream in14 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part14.rar"));
            InputStream in15 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part15.rar"));
            InputStream in16 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part16.rar"));
            InputStream in17 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part17.rar"));
            InputStream in18 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part18.rar"));
            InputStream in19 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part19.rar"));
            InputStream in20 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part20.rar"));
            InputStream in21 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part21.rar"));
            InputStream in22 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part22.rar"));
            InputStream in23 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part23.rar"));
            InputStream in24 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part24.rar"));
            InputStream in25 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part25.rar"));
            InputStream in26 = new FileInputStream(new File("D:\\迅雷下载\\Outlast_2.CHS.Green.v3.0-3DM\\3DMGAME-Outlast_2.CHS.Green.v3.0.part26.rar"));


            Vector<InputStream> v = new Vector<InputStream>();
            v.add(in1);
            v.add(in2);
            v.add(in3);
            v.add(in4);
            v.add(in5);
            v.add(in6);
            v.add(in7);
            v.add(in8);
            v.add(in9);
            v.add(in10);
            v.add(in11);
            v.add(in12);
            v.add(in13);
            v.add(in14);
            v.add(in15);
            v.add(in16);
            v.add(in17);
            v.add(in18);
            v.add(in19);
            v.add(in20);
            v.add(in21);
            v.add(in22);
            v.add(in23);
            v.add(in24);
            v.add(in25);
            v.add(in26);
            Enumeration es = v.elements();
            hebing(es);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    private static void hebing( Enumeration es){
        SequenceInputStream sis = new SequenceInputStream(es);
        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("D:\\360安全浏览器下载\\496.76-notebook-win10-win11-64bit-international-dch-whql.exe")));
            byte[] bytes = new byte[1024];
            int len = -1;
            while ((len = sis.read(bytes))!=-1){
                bos.write(bytes,0,len);
                bos.flush();
            }
            sis.close();
            bos.close();
            System.out.println("合并完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    private static void fenge(File target, int cutSize){
        if(target==null)return;
        int num = target.length()%cutSize==0?(int)target.length()/cutSize:
                (int)target.length()/cutSize+1;
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(target));
            BufferedOutputStream bos = null;
            int len = -1;
            byte[] bytes = null;
            int count = 0;
            for(int i=0;i<num;i++){
                bos =
                        new BufferedOutputStream(
                                new FileOutputStream(
                                        new File(
                                                "C:\\Users\\Administrator\\Desktop\\File\\"+(i+1)+"-temp-"+target.getName())));
                if(cutSize<=1024){
                    bytes = new byte[(int)cutSize];
                    count = 1;
                }else {
                    bytes = new byte[1024];
                    count =(int) cutSize/1024;
                }
                while (count>0 && (len=bis.read(bytes))!=-1){
                    bos.write(bytes,0,len);
                    bos.flush();
                    count--;
                }
                if(cutSize%1024!=0){
                    bytes = new byte[(int)cutSize%1024];
                    len = bis.read(bytes);
                    bos.write(bytes,0,len);
                    bos.flush();
                    bos.close();
                }else {
                    bos.close();
                }
            }
            System.out.println("分割完成");
               bis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
